package flyWeightPattern;

import java.util.HashMap;
import java.util.Map;

//工厂类：享元工厂类，用于创建享元对象
public class Factory {

    private Map<String,ChessPiece> chessPieceMap = new HashMap<>();

    //创建享元对象
    public ChessPiece getChessPiece(String type) {
        if (chessPieceMap.containsKey(type)) {
            return chessPieceMap.get(type);
        } else {
            ConcreteChessPiece chessPiece = new ConcreteChessPiece(type);
            chessPieceMap.put(type, chessPiece);
            return chessPiece;
        }
    }

}
